<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="./lib/react.development.js"></script>
    <script src="./lib/react-dom.development.js"></script>
    <script src="./lib/babel.min.js"></script>
</head>
<body>
<div id="root">

</div>

</body>
<script type="text/babel">
    // 父子  子父   非父子(兄弟,跨组件)
    const root = ReactDOM.createRoot(document.querySelector("#root"));
    let num = 100;
    // App组件中如果有一些数据,我想把数据传递给子组件Child
    class App extends React.Component{
        num = 1;// 实例属性
        username = "zhangsan";// 实例属性
        constructor() {
            super();
            this.age = 10000;// 实例属性
            this.state = {
                a:1,
                b:2,
                c:3,
                d:4
            }
        }
        render(){
            let num = 200;
            return (
                <div>
                    <h3>App-{this.num}</h3>
                    <Child num={this.num} username={this.username} age = {this.age}/>
                    <hr/>
                    <My a = {this.state.a} b={this.state.b} c={this.state.c} d={this.state.d}/>
                    <My {...this.state}/>
                </div>
            )
        }
    }
    class My extends React.Component{
        render(){
            return (
                <div>
                    <h3>My</h3>
                    <p>a:{this.props.a}</p>
                    <p>b:{this.props.b}</p>
                    <p>c:{this.props.c}</p>
                    <p>d:{this.props.d}</p>
                </div>
            )
        }
    }
    class Child extends React.Component{
        constructor(props) {
            super(props);
            console.log(props,this.props,props === this.props);// {num:1}
        }
        render(){
            return (
                <div>
                    <h3>Child</h3>
                    <p>num:{this.props.num}</p>
                    <p>age:{this.props.age}</p>
                    <p>username:{this.props.username}</p>
                </div>
            )
        }
    }
    root.render(<App/>);
</script>
</html>